package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_global_method")
public class OrderHystrixController {

    @Resource
    private PaymentHystixService paymentHystixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentinfo_Ok(@PathVariable("id") Integer id){
        return paymentHystixService.paymentinfo_Ok(id);
    }



    @GetMapping("/consumer/payment/hystrix/timeOut/{id}")
//    @HystrixCommand(fallbackMethod = "paymentTimeOutfallback",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    @HystrixCommand
    public String paymentinfo_TimeOut(@PathVariable("id") Integer id){
        int age = 10/0;
        return paymentHystixService.paymentinfo_TimeOut(id);
    }

    public String paymentTimeOutfallback(@PathVariable("id") Integer id){
        return "我是消费者80，对方支付系统繁忙请稍后再试或者自己出错请检查自己";
    }

    //下面是全局的fallbackMethod
    public String payment_global_method(){
        return "global异常处理信息请稍后再试";
    }
}
